package com.evildog.workspace.life.application.controller;

import com.evildog.workspace.common.result.Result;
import com.evildog.workspace.common.result.ResultGenerator;
import com.evildog.workspace.dependencies.mybatis.util.QueryConditionUtils;
import com.evildog.workspace.life.application.bo.AlbumsPhotoBO;
import com.evildog.workspace.life.application.bo.PhotoBO;
import com.evildog.workspace.life.application.convert.PhotoConvert;
import com.evildog.workspace.life.application.model.PhotoListParam;
import com.evildog.workspace.life.application.model.PhotoParam;
import com.evildog.workspace.life.application.model.PhotoStarParam;
import com.evildog.workspace.life.application.service.PhotoService;
import com.evildog.workspace.life.application.vo.AlbumsPhotoVO;
import com.evildog.workspace.life.application.vo.PhotoVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * photo Controller
 * 相片
 * </p>
 *
 * @author evildog
 * @since 2020-07-18
 */
@RestController
@RequestMapping("/photos")
@AllArgsConstructor
@Api(tags = "photo相关接口")
public class PhotoController {
    private PhotoService photoService;

    @PostMapping
    @ApiOperation(value = "添加接口")
    public Result<Boolean> save(@RequestBody PhotoParam photoParam) {
        return ResultGenerator.status(photoService.save(PhotoConvert.INSTANCE.convert(photoParam)));
    }

    @DeleteMapping("/{id}")
    @ApiOperation(value = "删除接口")
    public Result<Boolean> removeById(@PathVariable("id") Long id) {
        return ResultGenerator.status(photoService.removeById(id));
    }

    @DeleteMapping("/batch-remove")
    @ApiOperation(value = "批量删除接口")
    public Result<Boolean> delete(@RequestParam("ids") List<Integer> ids) {
        return ResultGenerator.status(photoService.removeByIds(ids));
    }

    @PatchMapping("/{id}/star")
    @ApiOperation(value = "更新star接口")
    public Result<Boolean> updateStar(@PathVariable("id") Long id, @RequestBody PhotoStarParam wishParam) {
        return ResultGenerator.status(photoService.updateStar(id, PhotoConvert.INSTANCE.convert(wishParam)));
    }

    @GetMapping("/{id}")
    @ApiOperation(value = "查询详情接口")
    public Result<PhotoVO> getById(@PathVariable("id") Long id) {
        PhotoBO photoBO = photoService.getDetailById(id);
        return ResultGenerator.success(PhotoConvert.INSTANCE.convert(photoBO));
    }

    @GetMapping("/list")
    @ApiOperation(value = "根据albumId查询下面的相片")
    public Result<List<AlbumsPhotoVO>> getList(PhotoListParam photoListParam) {
        List<AlbumsPhotoBO> photoListBO = photoService.getList(
                QueryConditionUtils.getQueryCondition(photoListParam),
                PhotoConvert.INSTANCE.convert(photoListParam));
        return ResultGenerator.success(PhotoConvert.INSTANCE.convertVO(photoListBO));
    }

}
